package com.example.tao.mycar;

import android.app.Activity;
import android.app.Application;

import com.avos.avoscloud.AVOSCloud;
import com.example.tao.mycar.entity.PersonDataEntity;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Tao on 2016/3/9.
 */
public class MyApplication extends Application{
    public static boolean DEBUG = true;
    public static final String TAG = "_TAG";
    private static MyApplication instance;
    private List<Activity> activities = null;

    private static final String APPID = "SPuBOHLDArPFlldYue7gW65a-gzGzoHsz";
    private static final String APPKEY = "oyYGeOw5FUqhOhmqFlyCPk7c";

    private static String passwordStr;

    private ArrayList<PersonDataEntity> timeHeightDataArray = new ArrayList<>();
    private ArrayList<PersonDataEntity> timeWeightDataArray = new ArrayList<>();

    public MyApplication() {
        activities = new LinkedList<>();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        AVOSCloud.initialize(this, APPID, APPKEY);

        /*测试向leancloud上发送数据
        AVObject testObject = new AVObject("TestObject");
        testObject.put("foo", "bar");
        testObject.saveInBackground();
        */
    }

    @Override
    public void onTerminate() {
        super.onTerminate();

    }

    public static MyApplication getInstance() {
        if (null == instance) {
            instance = new MyApplication();
        }
        return instance;
    }

    public void addActivity(Activity activity) {
        if (activity != null && activities.size() > 0) {
            if (!activities.contains(activity)) {
                activities.add(activity);
            }
        } else {
            activities.add(activity);
        }
    }

    public void exit() {
        if (activities != null && activities.size() > 0) {
            for (Activity activity : activities){
                activity.finish();
            }
        }
    }

    public static void setPassword(String passwordStr) {
        MyApplication.passwordStr = passwordStr;
    }

    public static String getPassword() {
        return passwordStr;
    }

    public void setUserHeightData(ArrayList<PersonDataEntity> arrayList) {
        this.timeHeightDataArray = arrayList;
    }
    public ArrayList<PersonDataEntity> getUserHeightData() {
        return timeHeightDataArray;
    }

    public void setUserWeightData(ArrayList<PersonDataEntity> arrayList) {
        this.timeWeightDataArray = arrayList;
    }
    public ArrayList<PersonDataEntity> getUserWeightData() {
        return timeWeightDataArray;
    }

}
